class MainRightClick {
	Main: egret.DisplayObject;

	constructor(Main: egret.DisplayObject) {
		this.Main = Main;
		window.document.addEventListener('mousedown', (ev) => {
			// 1 left  2 right 4 middle
			// eslint-disable-next-line no-bitwise
			if (ev.button & 2) {
				// MainWindow.ins().contexMenu.clearCurrentContex();
				MainWindow.ins().mode.onMouseRightDown();
				this.onMouseRightDown(ev);
			}
		});
	}

	static rightDownEvent = 'ENV_RIGHTDOWN'

	onMouseRightDown(ev: MouseEvent): void {
		// this.contexMenu.onRightClick()
		const [x, y] = mouse2Game(ev.x, ev.y, this.Main);
		const target = this.Main.stage.$hitTest(x, y);
		if (target) {
			// console.log("onMouseRight 2",target,x,y)
			target.dispatchEventWith(MainRightClick.rightDownEvent, true);
		}
	}
}
